import type { ProColumns } from '@ant-design/pro-components';
import { Button } from 'antd';
import deleteConfirm from '@/utils/deleteConfirm'
import { ActionType } from '@ant-design/pro-table';
import { deleteRecord } from '@/services/mz'
import type { ZYBLItem } from '@/interfaces/bl'
import WithAuthComp from '@/components/WithAuthComp';
import { ROLE } from '@/common/const'

const getColumns: (props) => ProColumns<ZYBLItem>[] = (props) => {
    const { addMedicalRef, fileAddRef, medicalDetailRef, setId } = props
    return [
        {
            title: '门诊号',
            dataIndex: 'recordId',
        },
        {
            title: '胸牌号',
            dataIndex: 'patientnumber',
        },
        {
            title: '姓名',
            dataIndex: 'name',
        },
        {
            title: '监区',
            dataIndex: 'jq',
        },
        {
            title: '门诊时间',
            key: 'showTime',
            dataIndex: 'mzDate',
            valueType: 'date',
            hideInSearch: true,
        },
        {
            title: '门诊时间',
            dataIndex: 'mzDate',
            valueType: 'dateRange',
            hideInTable: true,
            search: {
                transform: (value) => {
                    return {
                        mzStartDate: value[0],
                        mzEndDate: value[1],
                    };
                },
            },
        },
        {
            title: '科室',
            dataIndex: 'ks',
            valueType: 'select',
            valueEnum: {
                内科: {
                    text: '内科',
                },
                外科: {
                    text: '外科',
                },
                传染病: {
                    text: '传染病',
                },
            },
        },
        {
            title: '伤种',
            dataIndex: 'sz',
            valueType: 'select',
            valueEnum: {
                // 工伤 他伤 意外伤 自伤自残
                工伤: {
                    text: '工伤',
                },
                他伤: {
                    text: '他伤',
                },
                意外伤: {
                    text: '意外伤',
                },
                自伤自残: {
                    text: '自伤自残',
                },
            },
        },
        {
            title: '操作',
            valueType: 'option',
            key: 'option',
            width: 300,
            render: (text, record, _, action) => [
                <WithAuthComp authKey={[ROLE.YS, ROLE.HS]}>
                    <Button
                        size='small'
                        key="add"
                        type='primary'
                        onClick={() => {
                            // setReadonly(false)
                            setId(record.recordId)
                            addMedicalRef?.current?.showModelRef();
                        }}
                    >
                        新增病历
                    </Button>
                </WithAuthComp>
                ,
                <WithAuthComp authKey={[ROLE.YS, ROLE.HS, ROLE.ZL]}>
                    <Button
                        color="cyan"
                        size='small'
                        type='primary'
                        key="detail"
                        onClick={() => {
                            // setReadonly(true)
                            setId(record.recordId)
                            medicalDetailRef?.current?.showModelRef();
                        }}
                    >
                        详情
                    </Button>
                </WithAuthComp>
                ,
                <WithAuthComp authKey={[ROLE.YS, ROLE.HS]}>
                    <Button
                        size='small'
                        type='primary'
                        key="result"
                        ghost
                        onClick={() => {
                            // setReadonly(false)
                            setId(record.recordId)
                            fileAddRef?.current?.showModelRef();
                        }}
                    >
                        检验结果
                    </Button>
                </WithAuthComp>
                ,
                <WithAuthComp authKey={[ROLE.ADMIN]}>
                    <Button
                        size='small'
                        type="primary"
                        key="delete"
                        danger
                        onClick={() => {
                            deleteConfirm({ id: record.recordId, action: action as ActionType, deleteApi: deleteRecord })
                        }}
                    >
                        删除
                    </Button>
                </WithAuthComp>
                ,
            ],
        },
    ];
}

export default getColumns;